const {app, BrowserWindow, child_process} = require('electron');
const a = require('console')
const path = require('path')

function createWindows() {
    let win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            nodeIntergration: true
        }
    })

    win.loadFile('index.html')

    win.webContents.openDevTools()
}

app.whenReady().then(createWindows)

app.on('windows-all-closed', () => {
    if (process.platform == 'darwin') {

    }

    if (process.platform == 'win32') {
        app.quit()
    }
})


app.on('activate', () => {
    var myConsole = new a.Console(process.stdout, process.stderr);

    if (BrowserWindow.getAllWindows().length === 0) {
        createWindows()
    }


    var pyscript = path.dirname('./') + '/tools.py'
    myConsole.log(pyscript)

    // // TODO: 调用python脚本，可以通过shell或直接进程调用
    // const script = child_process.spawn(pyscript)
    // script.stdout.on('data', (data) => {
    //     myConsole.log('stdout: ${data}')
    // })

    // script.stderr.on('data', (data) => {
    //     myConsole.error('stderr: ${data}')
    // })

    // script.on('close', (code) => {
    //     myConsole.log('python script end.')
    // })

})
